package com.kjsdfgk.hjmdsf.ftvideo.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.kjsdfgk.hjmdsf.ftvdolist.mvp.ui.fragment.VdoListFragment;
import com.kjsdfgk.hjmdsf.ftvideo.di.component.DaggerVideoV3FtComponent;
import com.kjsdfgk.hjmdsf.ftvideo.mvp.contract.VideoV3FtContract;
import com.kjsdfgk.hjmdsf.ftvideo.mvp.presenter.VideoV3FtPresenter;
import com.kjsdfgk.hjmdsf.livev3.mvp.ui.activity.PagerFragmentStatePager;
import com.lksdkjs.live.R;


import java.util.ArrayList;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 04/30/2020 17:57
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class VideoV3FtFragment extends BaseFragment<VideoV3FtPresenter> implements VideoV3FtContract.View {

    public static VideoV3FtFragment newInstance() {
        VideoV3FtFragment fragment = new VideoV3FtFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerVideoV3FtComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }
    @BindView(R.id.layout_tabLayout)
    TabLayout mTabLayout;

    @BindView(R.id.layout_pager)
    ViewPager mViewPager;
    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_video_v3_ft, container, false);
    }
    public final String[] CATEGORY_VALUE = {"最新片源", "高清无码", "偷拍自拍", "日韩女优", "欧美激情", "成人动漫", "今日网红", "经典三级"};
    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mTabLayout.removeAllTabs();
        final ArrayList<Fragment> listFragments = new ArrayList<>();

        for (String str:CATEGORY_VALUE) {
            mTabLayout.addTab(mTabLayout.newTab().setText(str));
            Bundle bundle = new Bundle();
            bundle.putString( "category" , str );
            VdoListFragment fragment =  new VdoListFragment();
            fragment.setArguments(bundle);
            listFragments.add(fragment);
        }


        PagerFragmentStatePager pagerAdapter = new PagerFragmentStatePager(getChildFragmentManager());
        mViewPager.setAdapter(pagerAdapter);
        mViewPager.setOffscreenPageLimit(5);
        mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
        mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));

        pagerAdapter.setListFragments(listFragments);
        pagerAdapter.notifyDataSetChanged();
    }

    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading(String key) {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public boolean isCancel() {
        return false;
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }
}
